<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>递归组件</h2>
      <!-- <ul>
        <li v-for="(item, index) in list" :key="index">{{ item.name }}</li>
      </ul> -->
      <list :list="list"></list>
    </div>

    <script src="../Vue.js"></script>
    <script>
      const List = {
        props: ["list"],
        // name属性是用来做递归组件的
        name: "List",
        template: `
          <ul>
            <li v-for="(item, index) in list" :key="index">
              {{ item.name }}
              <list :list="item.children" v-if="item.children"></list>
            </li>
          </ul>
        `,
      };

      new Vue({
        el: "#app",
        data: {
          list: [
            {
              name: "浙江省",
              children: [
                {
                  name: "杭州市",
                  children: [
                    {
                      name: "西湖区",
                    },
                    {
                      name: "上城区",
                      children: [
                        {
                          name: "九堡街道",
                          children: [
                            {
                              name: "牛田社区",
                            },
                          ],
                        },
                      ],
                    },
                  ],
                },
                {
                  name: "宁波市",
                },
              ],
            },
            {
              name: "江苏省",
              children: [
                {
                  name: "南京市",
                },
                {
                  name: "苏州市",
                },
              ],
            },
          ],
        },
        components: {
          List,
        },
      });
    </script>
  </body>
</html>
